// 2023-3-33. express 实现 验证身份中间件（规则自定）
const express = require("express");
const server = express();
server.use("/user/:name", (req, res, next) => {
  console.log("运行l中间件");
  // 规则就是name为zz的时候跳转到user页面 用params获取路径
  console.log(req.params);
  let { name } = req.params;
  console.log(name);
  if (name == 'zz') {
    next()
    return;
  }
  res.redirect("/");
});

server.get("/user/:name", (req, res) => {
    res.send("欢迎来到用户页面");

});
server.get("/", (req, res) => {
  res.send("这是首页面");
});

server.listen(80, () => {
  console.log("success");
});
